package org.tigris.mappedlexer.validator.implementation;

/**
 * Checks if the input is number.
 * 
 * @author zhisen.huang
 *
 */
public class NumericValidator extends AbstractValidator {

	/**
	 * Get the next token with the constraints.
	 * 
	 * @param validators the constraints
	 */
	@Override
	public boolean validate(char chr) throws UnsupportedOperationException {
		return (chr >= '0' && chr <= '9');
	}

	/**
	 * Get the next token with the constraints.
	 * 
	 * @param validators the constraints
	 */
	@Override
	public boolean validate(String string) throws UnsupportedOperationException {
		boolean dotted = false;

		for (char chr : string.toCharArray()) {
			if (chr == '.') {
				if (dotted) {
					return false;
				}
				dotted = true;
			}
			else if (!validate(chr)) {
				return false;
			}
		}
		return true;
	}
}
